var app = getApp();
var $ = app.globalData;
import data from '../myadd/newadd/data.js'
Page({
	data: {
		options1: data,
		input: [],
		shopinfo:{},
		disabled:false,
		shenheid:''
	},
	onLoad: function(options) {
		var that = this
		// 判断用户是否是登录状态
		if (!$.userinfo) {
			// wx.navigateBack({})
		} else {
			this.setData({
				userinfo: $.userinfo
			})
			// 判断是否有店铺正在审核
			wx.request({
				url: $.AdminUrl + "/YApi/shop_apply",
				data: {
					customerid: $.userinfo.id
				},
				success: function(data) {
					if (data.data.code == 2) {
						that.setData({
							disabled:'申请信息审核中',
							shopinfo:data.data.obj,
							title1:data.data.obj.province+" "+data.data.obj.city+" "+data.data.obj.district
						})
					}else if(data.data.code == 3){
						console.log(123)
						var datab = data.data.obj
						var add = [{label:""},{label:""},{label:""}];
						var input = new Array
						add[0].label = datab.province
						add[1].label = datab.city
						add[2].label = datab.district
						input[0] = datab.realname
						input[1] = datab.phone
						input[2] = datab.shopname
						input[3] = datab.address
						that.setData({
							disabled: '修改信息,重新审核',
							add:add,
							shenheid:datab.id,
							shopinfo:datab,
							input:input,
							title1:datab.province+" "+datab.city+" "+datab.district
						})
					}
					console.log(data)
				}
			})
		}
	},
	// 获取输入信息
	input: function(e) {
		var that = this
		var index = e.currentTarget.dataset.ind
		var val = e.detail.value
		var input = that.data.input
		input[index] = val
		that.setData({
			input: input
		})
	},
	onOpen1() {
		this.setData({
			visible1: true
		})
	},
	onClose1() {
		this.setData({
			visible1: false
		})
	},
	// 地址
	onChange1(e) {
		this.setData({
			title1: e.detail.options.map((n) => n.label).join('/'),
			add: e.detail.options
		})
		console.log('onChange1', e.detail.options)
	},
	// 提交申请
	gotologin: function() {
		var that = this
		var input = that.data.input
		var add = that.data.add
		if (input[0] == '') {
			wx.showToast({
				title: "请输入真实姓名",
				duration: 3000,
			})
		} else if (input[1] == '') {
			wx.showToast({
				title: "请输入店铺电话",
				duration: 3000,
			})
		} else if (input[2] == '') {
			wx.showToast({
				title: "请输入店铺名称",
				duration: 3000,
			})
		} else if (input[3] == '') {
			wx.showToast({
				title: "请输入详细地址",
				duration: 3000,
			})
		} else if (add.length < 2) {
			wx.showToast({
				title: "请选择店铺地址",
				duration: 3000,
			})
		} else {
			wx.request({
				url: $.AdminUrl + "/YApi/shopapply_sub",
				data: {
					customerid: $.userinfo.id,
					loginname: $.userinfo.loginname,
					realname: input[0],
					phone: input[1],
					shopname: input[2],
					province: add[0].label,
					city: add[1].label,
					district: add[2].label,
					address: input[3],
					id:that.data.shenheid
				},
				success: function(data) {
					if (data.data.code) {
						wx.showToast({
							title: data.data.msg,
							duration: 3000,
						})
						setTimeout(function(){
							wx.navigateBack({})
						},3000)
					} else {
						wx.showToast({
							icon: "none",
							title: data.data.msg,
							duration: 3000,
						})
					}
				}
			})
		}
		console.log(this.data.input)
	},
	onShow: function() {

	},
})
